/*
 *MIT License
 *Copyright (c) 2021 fullset
 *@ClassName SysRoleController
 *@date 2021/7/10 10:04
 *@author: pangps
 *@Description TODO
 */
package com.fs.base.controller;

import com.fs.base.service.SysRoleService;
import com.fs.core.web.BaseResult;
import com.fs.orm.entity.SysRole;
import com.fs.orm.vo.form.SysRoleForm;
import com.fs.orm.vo.form.SysUserForm;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags="角色服务接口")
@RestController
@RequestMapping("/baseService/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @ApiOperation(value = "角色列表", notes = "")
    @PostMapping(value ="/layTable")
    public BaseResult<List<SysRole>> getLayTable(@RequestBody Map<String, Object> params) {
        PageInfo<SysRole> pageInfo = sysRoleService.getLayTable(params);
        Long count = pageInfo.getTotal();
        return new BaseResult<>(count.intValue(), pageInfo.getList());
    }

    @ApiOperation(value="初始化角色表单")
    @PostMapping("/initForm")
    public BaseResult<SysRoleForm> initForm() {
        return new BaseResult<>(sysRoleService.initForm());
    }

    @ApiOperation(value="编辑角色表单")
    @PostMapping("/editForm/{id}")
    public BaseResult<SysRoleForm> editForm(@PathVariable Long id) {
        return new BaseResult<>(sysRoleService.editForm(id));
    }

    @ApiOperation(value = "添加角色", notes = "")
    @PostMapping(value ="/addRole")
    public BaseResult<SysRoleForm> addRole(@RequestBody SysRoleForm sysRoleForm) throws Exception {
        return new BaseResult<>(sysRoleService.addRole(sysRoleForm));
    }

    @ApiOperation(value = "删除角色", notes = "逻辑删除")
    @PostMapping(value ="/logicalDel/{id}")
    public BaseResult<Boolean> logicalDel(@PathVariable String id)  {
        return new BaseResult<>(sysRoleService.logicalDeleteById(id));
    }

    @ApiOperation(value = "批量删除角色", notes = "逻辑删除")
    @PostMapping(value ="/batchDel/{ids}")
    public BaseResult<Boolean> batchDel(@PathVariable String ids)  {
        return new BaseResult<>(sysRoleService.batchDel(ids));
    }

    @ApiOperation(value = "编辑角色", notes = "")
    @PostMapping(value ="/editRole")
    public BaseResult<SysRoleForm> editRole(@RequestBody SysRoleForm sysRoleForm) {
        return new BaseResult<>(sysRoleService.editRole(sysRoleForm));
    }

}
